// DirectionRequest object
//{
//  origin: LatLng | String, //LatLng obj or "Chicago, IL"
//  destination: LatLng | String,
//  travelMode: TravelMode, //google.maps.TravelMode.WALKING
//  transitOptions: TransitOptions,
//  unitSystem: UnitSystem, //UnitSystem.METRIC
//  durationInTraffic: Boolean,
//  waypoints[]: DirectionsWaypoint,
//  optimizeWaypoints: Boolean,
//  provideRouteAlternatives: Boolean,
//  avoidHighways: Boolean,
//  avoidTolls: Boolean
//  region: String // "it"
//}
// Initiating a directions request to the DirectionsService with the route() method
// requires passing a callback which executes upon completion of the service request.
// This callback will return a DirectionsResult and a DirectionsStatus code in the response.

directionsDisplay = null;
directionsService = new google.maps.DirectionsService();

function initDR() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  directionsDisplay.setMap(mapBo.getMap());
  //pulisco il div prima di stampare le indicazioni
  //document.getElementById("directionsPanel").innerHTML = "";
  directionsDisplay.setPanel(document.getElementById("mypanel"));
  //$( "#mypanel" ).trigger( "updatelayout" );
  


}

function calcRoute(start, end) {
//  var start = origin;
//  var end = destination;
  var request = {
    origin: start,
    destination: end,
    travelMode: google.maps.TravelMode.WALKING,
    unitSystem: google.maps.UnitSystem.METRIC,
    region: "it"
  };
  
  initDR();
  
  directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(result);
    }
  });
}

function directionsOverlay(){
	return directionsDisplay;
}


function deleteRoute(){
	directionsDisplay.setMap(null);
	directionsDisplay = null;
	deactivateDirections();
}

